//
//  SHBorderLabel.m
//  psd
//
//  Created by Mr.Xr on 2017/8/9.
//  Copyright © 2017年 Mr.Xr All rights reserved.
//

#import "SHBorderLabel.h"

@implementation SHBorderLabel


- (instancetype)init
{
    self = [super init];
    if (self) {
        
    }
    return self;
}

-(void)awakeFromNib{
    [super awakeFromNib];
}

- (void)drawTextInRect:(CGRect)rect
{
    CGRect realRect = CGRectMake(rect.origin.x+self.borderWidth*0.5, rect.origin.y, rect.size.width, rect.size.height);
    CGSize shadowOffset = self.shadowOffset;
    UIColor *textColor = self.textColor;
    
    CGContextRef c = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(c, self.borderWidth);
    CGContextSetLineJoin(c, kCGLineJoinRound);
    
    CGContextSetTextDrawingMode(c, kCGTextStroke);
    self.textColor = _borderColor;
    
    [super drawTextInRect:realRect];
    
    CGContextSetTextDrawingMode(c, kCGTextFill);
    self.textColor = textColor;
    self.shadowOffset = CGSizeMake(0, 0);
    [super drawTextInRect:realRect];
    
    self.shadowOffset = shadowOffset;
}

-(void)setBorderWidth:(CGFloat)borderWidth
{
    _borderWidth = borderWidth;
    [self setNeedsDisplay];
}

-(void)setFontSize:(CGFloat)fontSize
{
    _fontSize = fontSize;
	if(self.font) {
		self.font = [UIFont fontWithName:self.font.fontName size:fontSize];
	}else {
		self.font = [UIFont systemFontOfSize:fontSize];
	}
}

-(void)setScaleFontSize:(CGFloat)scaleFontSize{
    _scaleFontSize = scaleFontSize;
    self.fontSize = scaleFontSize * SCALE_6S_W;
}

-(void)setBorderColor:(UIColor *)borderColor{
    _borderColor = borderColor;
    [self setNeedsDisplay];
}


- (CGSize)intrinsicContentSize {
    CGSize size = [super intrinsicContentSize];
    return CGSizeMake(size.width + self.borderWidth, size.height);
}


@end
